package com.itcpeng.jobs;

import com.itcpeng.constant.RedisConstant;
import com.itcpeng.util.QiNiuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class MyJobs {

    @Autowired
    private JedisPool jedisPool;

    public void run() {
        Jedis jedis = jedisPool.getResource();
        //取出redis中所有图片集合 保存到数据库的图片集合
        Set<String> sdiff = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        //调用qiniu删除服务器上的图片
        QiNiuUtil.removeFiles(sdiff.toArray(new String[]{}));
        //成功就删除redis中的缓存
        jedis.del(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
    }

    public static void main(String[] args) {
        new ClassPathXmlApplicationContext("applicationContext-jobs.xml");
    }
}
